import typing

from server.resource.util.Serializable import Serializable


class ApiResponse(Serializable):
    code: int
    message: str
    data: typing.Any

    @classmethod
    def success(cls, data=None):
        if data:
            return cls(code=200, message='操作成功', data=data)
        return cls(code=200, message='操作成功', data=None)

    @classmethod
    def server_error(cls,message=None):
        if message:
            return cls(code=500,message=message,data=None)
        return cls(code=500, message='服务器异常', data=None)
